package com.alex.index.insert.nsfctest;

import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 葛成瑞
 * @Date: 2025/4/8 15:45
 */
@Data
public class Article {

    private String id;
    private String title;
    private List<AuthorAffiliation> authors = new ArrayList<>();

    // 处理原始数据
    public void processRawData(List<Map<String, Object>> rawInstitutions) {
        Map<String, AuthorAffiliation> authorMap = new HashMap<>();
        for (Map<String, Object> inst : rawInstitutions) {
            String unit = (String) inst.get("unit");
            List<String> depts = (List<String>) inst.get("deptList");
            List<String> authors = (List<String>) inst.get("authList");
            for (String authorName : authors) {
                String auname = authorName;
                AuthorAffiliation aa = authorMap.computeIfAbsent(auname, k -> new AuthorAffiliation(auname));
                aa.addUnit(unit);  // 自动去重
                aa.addDepts(depts); // 自动去重
            }
        }
        this.authors.addAll(authorMap.values());
    }
}
